﻿#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int maxProfit(int* prices, int pricesSize) {
    if (pricesSize == 0) return 0;

    int minPrice = prices[0];
    int maxProfit = 0;

    for (int i = 1; i < pricesSize; ++i) {
        if (prices[i] < minPrice) {
            minPrice = prices[i];
        } else if (prices[i] - minPrice > maxProfit) {
            maxProfit = prices[i] - minPrice;
        }
    }

    return maxProfit;
}

int main() {
    int prices[] = {11,5,4,9,3,4,2,8};
    int size = sizeof(prices) / sizeof(int);
    int profit = maxProfit(prices, size);
    printf("The max profit is  --- %d \n", profit);
    return 0;
}